package com.huishen.edrivenew.bean;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.huishen.edrivenew.base.BaseBean;
import com.huishen.edrivenew.util.TLog;

/**
 * 详情
 * @author wu
 *
 */
//backoff //倒车入库
//ramp //斜坡定点停车
//side //侧方位停车
//turn //直角转弯
//curve //S曲线
//bridge //单边桥
//count  //培训次数 ， pass//通过率，points//扣分项（content//内容，pointValue//分值）
//说明：distance//距离， price//价格   ，lessonDate//日期，  time//时间 ，   timeFrame//课时 ，  subject//科目

public class DetialBean extends BaseBean {
    
    public int subject;
    
    public int coachId;
    public String coachName;
    public int distance;
    public String lessonDate;
    public int price;
    public int stuId;
    public String time;
    public String timeFrame;
    
    public DetialInBean backoff;
    public DetialInBean bridge;
    public DetialInBean curve;
    public DetialInBean ramp;
    public DetialInBean side;
    public DetialInBean turn;
    
    public List<Detial3Bean> detial3List = new ArrayList<Detial3Bean>();
    
    
    public DetialInBean getkm2Bean(int index) {
        switch(index) {
            case 0:
                if(backoff == null) {
                    return null;
                }
                backoff.name = "倒车入库";
              return backoff;
            case 1:
                if(bridge == null) {
                    return null;
                }
                bridge.name = "单边桥";
              return bridge;
            case 2:
                if(curve == null) {
                    return null;
                }
                curve.name = "S曲线";
              return curve;
            case 3:
                if(ramp == null) {
                    return null;
                }
                ramp.name = "斜坡定点停车";
              return ramp;
            case 4:
                if(side == null) {
                    return null;
                }
                side.name = "侧方位停车";
              return side;
            case 5:
                if(turn == null) {
                    return null;
                }
                turn.name = "直角转弯";
              return turn;
        }
        return null;
    }
    
    
    
    public static BaseBean parseJson(JSONObject jsonObj) {
        DetialBean bean = new DetialBean();
        bean.code = jsonObj.optInt("code");
        bean.subject = jsonObj.optInt("subject");
        
        JSONObject km2Json = jsonObj.optJSONObject("km2Info");
        if(km2Json != null) {
            bean.coachId = km2Json.optInt("coachId");
            bean.coachName = km2Json.optString("coachName");
            bean.distance = km2Json.optInt("distance");
            bean.lessonDate = km2Json.optString("lessonDate");
            bean.price = km2Json.optInt("price");
            bean.stuId = km2Json.optInt("stuId");
            bean.time = km2Json.optString("time");
            bean.timeFrame = km2Json.optString("timeFrame");
            
            JSONObject SimulData = km2Json.optJSONObject("SimulData");
            if(SimulData != null) {
                JSONObject curve = SimulData.optJSONObject("curve");
                JSONObject backoff = SimulData.optJSONObject("backoff");
                JSONObject bridge = SimulData.optJSONObject("bridge");
                JSONObject ramp = SimulData.optJSONObject("ramp");
                JSONObject side = SimulData.optJSONObject("side");
                JSONObject turn = SimulData.optJSONObject("turn");
                if(curve != null) {
                    bean.curve = new Gson().fromJson(curve.toString(), DetialInBean.class);
                }
                if(backoff != null) {
                    bean.backoff = new Gson().fromJson(backoff.toString(), DetialInBean.class);
                }
                if(bridge != null) {
                    bean.bridge = new Gson().fromJson(bridge.toString(), DetialInBean.class);
                }
                if(ramp != null) {
                    bean.ramp = new Gson().fromJson(ramp.toString(), DetialInBean.class);
                }
                if(side != null) {
                    bean.side = new Gson().fromJson(side.toString(), DetialInBean.class);
                }
                if(turn != null) {
                    bean.turn = new Gson().fromJson(turn.toString(), DetialInBean.class);
                }
            }
        }
        
        JSONObject km3Json = jsonObj.optJSONObject("km3Info");
        if(km3Json != null) {
            bean.coachId = km3Json.optInt("coachId");
            bean.coachName = km3Json.optString("coachName");
            bean.distance = km3Json.optInt("distance");
            bean.lessonDate = km3Json.optString("lessonDate");
            bean.price = km3Json.optInt("price");
            bean.stuId = km3Json.optInt("stuId");
            bean.time = km3Json.optString("time");
            bean.timeFrame = km3Json.optString("timeFrame");
            
            JSONArray SimulData3 = km3Json.optJSONArray("SimulData");
            if(SimulData3 != null) {
                for(int i=0;i<SimulData3.length();i++) {
                    JSONObject obj3 = SimulData3.optJSONObject(i);
                    try {
                        if(obj3 != null) {
                            JSONArray array = obj3.names();
                            String name = array.opt(0).toString();
                            if(name != null) {
                                Detial3Bean bean3 = new Detial3Bean();
                                bean3.name = name;
                                JSONObject jsonBean = obj3.optJSONObject(name);
                                bean3.scene = jsonBean.optInt("scene");
                                bean3.scene_pass = jsonBean.optInt("scene_pass");
                                
                                JSONArray points = jsonBean.optJSONArray("points");
                                if(points != null && points.length()!=0) {
                                    for(int j=0;j<points.length();j++) {
                                        JSONObject jsonPoint = points.optJSONObject(j);
                                        if(jsonPoint != null) {
                                            PointBean pointBean = new PointBean();
                                            pointBean.content = jsonPoint.optString("content");
                                            pointBean.pointValue = jsonPoint.optInt("pointValue");
                                            
                                            if(bean3.points == null) {
                                                bean3.points = new ArrayList<PointBean>();
                                            }
                                            bean3.points.add(pointBean);
                                        }
                                        
                                    }
                                }
                                
                                bean.detial3List.add(bean3);
                            }
                            
                        }
                    }catch(Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        
        return bean;
    }
    
    
    
    
    

    
    
    
    

    
}
